﻿using BielskoNoca.DAL.Abstract;
using BielskoNoca.DAL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BielskoNoca.DAL.Concrete
{
    public class SerieRepository : ISerieRepository
    {
        private BielskoNocaDataEntities context;
         
        public SerieRepository(BielskoNocaDataEntities context)
        {
            this.context = context;
        }

        public IQueryable<Models.Serie> Query
        {
            get { return this.context.Series; }
        }

        public Models.Serie GetFirstOrDefault(System.Linq.Expressions.Expression<Func<Models.Serie, bool>> whereCondition)
        {
            return this.context.Series.Single(whereCondition);
        }

        public int Add(Models.Serie entity)
        {
            Serie tEntity = this.context.Series.Add(entity);
            this.context.SaveChanges();

            return tEntity.Id;
        }

        public void Delete(Models.Serie entity)
        {
            throw new NotImplementedException();
        }

        public void Attach(Models.Serie entity)
        {
            throw new NotImplementedException();
        }

        public IList<Models.Serie> GetAll(System.Linq.Expressions.Expression<Func<Models.Serie, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public IList<Models.Serie> GetAll()
        {
            return this.Query.ToList();
        }

        public long Count(System.Linq.Expressions.Expression<Func<Models.Serie, bool>> whereCondition)
        {
            throw new NotImplementedException();
        }

        public long Count()
        {
            throw new NotImplementedException();
        }

        public Serie GetById(int id)
        {
            return this.GetFirstOrDefault(con => con.Id == id);
        }
    }
}